//------------------------------------------------------------------------------
// <pcdd-entitiy>
//     彩票主流业务类库
//     中奖类型业务对象
// </pcdd-entitiy>
//------------------------------------------------------------------------------ 

using CL.Enum.Common;
using CL.Game.DAL;
using CL.Game.Entity;
using CL.Redis.BLL;
using CL.Tools.Common;
using CL.View.Entity.Game;
using System.Collections.Generic;

namespace CL.Game.BLL
{

    /// <summary>
    /// WinTypesBLL 业务
    /// </summary>
    public class WinTypesBLL
    {
        WinTypesDAL dal = new WinTypesDAL(DbConnectionEnum.CaileGame);

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int ModifyEntity(WinTypesEntity entity)
        {
            return dal.ModifyEntity(entity);
        }
        /// <summary>
        /// 插入对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int InsertEntity(WinTypesEntity entity)
        {
            return dal.InsertEntity(entity);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsCode(int WinCode)
        {
            return dal.ExistsCode(WinCode);
        }
        /// <summary>
        /// 根据彩种编号查询
        /// </summary>
        /// <param name="LotteryCode"></param>
        /// <returns></returns>
        public List<WinTypesEntity> QueryEntitysByLotteryCode(int LotteryCode)
        {
            return dal.QueryEntitysByLotteryCode(LotteryCode);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public WinTypesEntity QueryEntity(int id)
        {
            return dal.Get(id);
        }
        /// <summary>
        /// 查询是否存在记录
        /// 后台调用
        /// </summary>
        /// <param name="WinCode">奖等编码</param>
        /// <param name="message">信息</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        public bool QueryExistsCode(int WinCode, ref string message, ref string status)
        {
            bool result = false;
            if (WinCode <= 0)
            {
                message = "请输入奖等编码";
                status = "n";
            }
            else
            {
                if (this.ExistsCode(WinCode))
                {
                    message = "奖等编码已被占用，请更换！";
                    status = "n";
                }
                else
                {
                    message = "奖等编码可使用";
                    status = "y";
                    result = true;
                }
            }
            return result;
        }
        /// <summary>
        /// 查询是否存在记录
        /// 后台调用
        /// </summary>
        /// <param name="Id">主键</param>
        /// <param name="message">引用信息</param>
        /// <returns></returns>
        public bool QueryExists(int Id, ref string message)
        {
            bool result = false;
            if (Id == 0)
                message = "传输参数不正确";
            else
            {
                if (!dal.Exists(Id))
                    message = "信息不存在或已被删除";
                else
                    result = true;
            }
            return result;
        }
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="WinID"></param>
        /// <returns></returns>
        public bool DelEntity(int WinID)
        {
            return dal.DelEntity(WinID);
        }
        /// <summary>
        /// 获取奖等视图分页数据
        /// </summary>
        /// <param name="LotteryCode">彩种编号</param>
        /// <param name="strName">奖等名称(模糊搜索)</param>
        /// <param name="orderby">排序条件</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="recordCount">总条数</param>
        /// <returns></returns>
        public List<udv_WinTypes> QueryListByPage(int LotteryCode, string strName, string orderby, int pageSize, int pageIndex, ref int recordCount)
        {
            return dal.QueryListByPage(LotteryCode, strName, orderby, pageSize, pageIndex, ref recordCount);
        }

        /// <summary>
        /// 查询对象集
        /// </summary>
        /// <param name="LotteryCode"></param>
        /// <returns></returns>
        public List<WinTypesEntity> QueryList(int LotteryCode)
        {
            SpecialRedis Special = new SpecialRedis();
            string CacheKey = string.Format("Cache_WinTypes_{0}", LotteryCode);
            List<WinTypesEntity> Rec = CacheHelper.Get<List<WinTypesEntity>>(CacheKey);
            if (Rec == null || Rec.Count == 0)
            {
                Rec = Special.QueryWinTypes(LotteryCode);
                if (Rec == null || Rec.Count == 0)
                {
                    Rec = this.QueryEntitysByLotteryCode(LotteryCode);
                    if (Rec != null && Rec.Count > 0)
                    {
                        Special.SetWinTypes(LotteryCode, Rec);
                        CacheHelper.Insert(CacheKey, Rec, 1440);
                    }
                }
                else
                    CacheHelper.Insert(CacheKey, Rec, 1440);
            }
            return Rec;
        }
    }
}
